<?php

namespace Spider\Weibo\Config;

class Config
{
    private array $config;
    private static ?Config $instance = null;

    private function __construct(array $config)
    {
        $this->config = array_merge([
            'redis' => [
                'host' => '127.0.0.1',
                'port' => 6379,
                'auth' => '',
                'db' => 0
            ],
            'request' => [
                'max_retries' => 3,
                'retry_delay' => 1,
                'timeout' => 10
            ]
        ], $config);
    }

    public static function init(array $config): void
    {
        self::$instance = new self($config);
    }

    public static function getInstance(): self
    {
        if (self::$instance === null) {
            throw new \RuntimeException('Config not initialized');
        }
        return self::$instance;
    }

    public function getRedis(): array
    {
        return $this->config['redis'];
    }

    public function getRequest(): array
    {
        return $this->config['request'];
    }
}
